package site.marqstree.kotlin.library.good.ui.activity.detail.sku

import android.app.Activity
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import android.widget.PopupWindow
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.mcxtzhang.lib.AnimShopButton
import com.mcxtzhang.lib.IOnAddDelListener
import kotlinx.android.synthetic.main.sku_selector.view.*
import site.marqstree.kotlin.library.base.data.net.observer.RxObserver
import site.marqstree.kotlin.library.base.data.net.request.RxRequest
import site.marqstree.kotlin.library.base.extent.json2Bean
import site.marqstree.kotlin.library.base.ui.popwin.BasePopWin
import site.marqstree.kotlin.library.base.util.rxbus.RxBus
import site.marqstree.kotlin.library.good.R
import site.marqstree.kotlin.library.good.databinding.SkuSelectorBinding
import site.marqstree.kotlin.library.good.ui.activity.detail.sku.event.EventAddCart
import site.marqstree.kotlin.library.good.ui.bean.GoodDetailBean
import site.marqstree.kotlin.library.provider.router.ProviderRouter


/*
 * 项目名: KotlinMall
 * 包名: site.marqstree.kotlin.library.good.ui.activity.detail.sku
 * 文件名: GoodsSkuPopWin
 * 创建者: marqstree
 * 创建时间: 2020/3/15 21:20
 * 描述: 商品SKU弹层
 */
class GoodsSkuPopWin(activity: Activity
                     ,val mGoodDetailBean: GoodDetailBean)
    : BasePopWin<SkuSelectorBinding>(activity, R.layout.sku_selector){

    init{
        mDataBinding.goodDetailBean = mGoodDetailBean

        initView()
    }

    private fun initView() {
        //关闭按钮
        mRootView.mCloseIcon.setOnClickListener {
            dismiss()
        }

        //初始化RecyclerView
        val mSkuContainerRv = mRootView.findViewById<RecyclerView>(R.id.mSkuContainerRv)
        mSkuContainerRv.layoutManager = LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL,false)
        val defautSkus: List<String> = mGoodDetailBean.defaultSku.split(",")
        mSkuContainerRv.adapter = SkuRvAdapter(mGoodDetailBean.skus.toMutableList())

        val mGoodNumberBtn = mRootView.findViewById<AnimShopButton>(R.id.mGoodNumberBtn)
        mRootView.mAddCartBtn.setOnClickListener{
            RxBus.send(EventAddCart(
                mGoodDetailBean.id,
                mGoodNumberBtn.count
                ))
            dismiss()
        }
    }
}